package com.yswwpp.cross.http;

/**
 * 请求行
 * 
 * @author yswwp
 *
 */
public class RequestLine
{
	/**
	 * 请求行分隔符：一个空格<br>
	 * 请求行格式如下（注意，其中+只是示范作用，协议中不存在）：<br>
	 * 请求方法+空格+URL+空格+协议版本
	 */
	private static final String REQUEST_LINE_DISPERSER = " ";
	/**
	 * 请求方法
	 */
	private HttpMethod method;
	/**
	 * 请求url
	 */
	private String url;
	/**
	 * 请求协议版本
	 */
	private String version;

	/**
	 * 
	 * @Title:RequestLine 
	 * @Description: 通过请求行直接构造
	 * @param requestLine 请求方法+空格+URL+空格+协议版本
	 */
	public RequestLine(String requestLine)
	{
		super();
		if (requestLine == null)
			throw new IllegalArgumentException("参数requestLine不能为null");

		String[] arr = requestLine.split(REQUEST_LINE_DISPERSER);
		if (arr == null || arr[0] == null || arr[1] == null || arr[2] == null)
			throw new IllegalArgumentException("参数requestLine格式不正确");

		method = HttpMethod.valueOf(arr[0].toUpperCase());

		url = arr[1];

		version = arr[2];

	}

	public RequestLine(HttpMethod method, String url, String version)
	{
		super();
		this.method = method;
		this.url = url;
		this.version = version;
	}

	public HttpMethod getMethod()
	{
		return method;
	}

	public void setMethod(HttpMethod method)
	{
		this.method = method;
	}

	public String getUrl()
	{
		return url;
	}

	public void setUrl(String url)
	{
		this.url = url;
	}

	public String getVersion()
	{
		return version;
	}

	public void setVersion(String version)
	{
		this.version = version;
	}

	@Override
	public String toString()
	{
		return "RequestLine [method=" + method + ", url=" + url + ", version="
				+ version + "]";
	}

}
